package com.kim.stream.rabbitmq.service.impl;

import com.kim.stream.rabbitmq.service.MessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.messaging.Source;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.UUID;


/**
 * @author KimWu
 * @date 2020/6/3 20:58
 * @Description ：
 */
@EnableBinding(Source.class) //定义消息的推送管道
@Slf4j
public class MessageServiceImpl implements MessageService {

    @Resource
    private MessageChannel output; //消息发送管道

    @Override
    public String send() {
        String s = UUID.randomUUID().toString();
        output.send(MessageBuilder.withPayload(s).build());
        log.info(" stream mq send success");
        return s;
    }
}
